# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=haka
pkgver=v0.3.0.r222.g37ae3090
pkgrel=1
epoch=1
groups=('blackarch' 'blackarch-networking' 'blackarch-sniffer')
pkgdesc='A collection of tool that allows capturing TCP/IP packets and filtering them based on Lua policy files.'
arch=('x86_64' 'aarch64')
url='https://github.com/haka-security/haka'
license=('Mozilla2')
depends=('libpcap' 'wireshark-cli' 'rsync' 'gawk' 'libedit' 'pcre' 'ncurses'
         'lua' 'libnetfilter_queue' 'capstone' 'geoip')
makedepends=('cmake' 'swig' 'iniparser' 'doxygen')
source=("git+https://github.com/haka-security/$pkgname")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd $pkgname

  sed -i 's|${CMAKE_INSTALL_PREFIX}/sbin|${CMAKE_INSTALL_PREFIX}/bin|' \
    CMakeLists.txt
  sed -i 's|-Wall -Werror|-Wall -Werror -lm|' CMakeLists.txt
  sed -i 's|-D_FORTIFY_SOURCE=2|-D_FORTIFY_SOURCE=2 -lm|' CMakeLists.txt

  sed -i '/add_subdirectory(test)/d' "lib/$pkgname/CMakeLists.txt"

  git submodule init
  git submodule update

}

build() {
  cd $pkgname

  mkdir -p make

  cd make

  cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr ..

  make
}

package() {
  cd $pkgname

  cd make

  make DESTDIR="$pkgdir" install

  mv "$pkgdir/usr/sbin/"{haka,hakactl} "$pkgdir/usr/bin"
  rmdir "$pkgdir/usr/sbin"
}

